/*************************************************************************
	> File Name: 020.有效的括号.c
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 五  9/ 3 16:02:27 2021
 ************************************************************************/

int getValue(char c) {
    if (c == ')') return '(';
    if (c == ']') return '[';
    if (c == '}') return '{';
    return 0;
}

bool isValid(char * s){
    int sta[strlen(s) + 1], top = 0;
    for (int i = 0; s[i]; i++) {
        int ch = getValue(s[i]);
        if (ch) {
            if (top == 0 || sta[top - 1] != ch) 
                return false;
            top--;
        } else {
            sta[top++] = s[i];
        }
    }
    return top == 0;
}
